package com.qr.service.wmyw.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyw.QrShoppingCart;
import com.qr.bean.wmyw.QrShoppingCartView;
import com.qr.controller.WmywBase;
import com.qr.mapper.wmyw.QrShoppingCartMapper;
import com.qr.mapper.wmyw.QrShoppingCartMapperView;
import com.qr.service.wmyw.QrShoppingCartService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/13 10:26:17
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class QrShoppingCartServiceImpl implements QrShoppingCartService{
    @Autowired
    private QrShoppingCartMapper qrShoppingCartMapper;

    @Autowired
    private QrShoppingCartMapperView qrShoppingCartMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<QrShoppingCart> InitWrapper(QrShoppingCart where){
        QueryWrapper<QrShoppingCart> whereWrapper = new QueryWrapper<QrShoppingCart>();
        if(where.getCart_id()!=null){
			whereWrapper.eq("cart_id",where.getCart_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getCategory_id()!=null){
			whereWrapper.eq("category_id",where.getCategory_id());
		}
        if(where.getName()!=null){
			whereWrapper.eq("name",where.getName());
		}
        if(where.getLogo()!=null){
			whereWrapper.eq("logo",where.getLogo());
		}
        if(where.getMin_buy()!=null){
			whereWrapper.eq("min_buy",where.getMin_buy());
		}
        if(where.getUnit()!=null){
			whereWrapper.eq("unit",where.getUnit());
		}
        if(where.getIntro()!=null){
			whereWrapper.eq("intro",where.getIntro());
		}
        if(where.getDescription()!=null){
			whereWrapper.eq("description",where.getDescription());
		}
        if(where.getTags()!=null){
			whereWrapper.eq("tags",where.getTags());
		}
        if(where.getCreate_time()!=null){
			whereWrapper.eq("create_time",where.getCreate_time());
		}
        if(where.getUnsend()!=null){
			whereWrapper.eq("unsend",where.getUnsend());
		}
        if(where.getSpec_id()!=null){
			whereWrapper.eq("spec_id",where.getSpec_id());
		}
        if(where.getSpec_name()!=null){
			whereWrapper.eq("spec_name",where.getSpec_name());
		}
        if(where.getPrice()!=null){
			whereWrapper.eq("price",where.getPrice());
		}
        if(where.getOriginal_price()!=null){
			whereWrapper.eq("original_price",where.getOriginal_price());
		}
        if(where.getPackage_price()!=null){
			whereWrapper.eq("package_price",where.getPackage_price());
		}
        if(where.getInventory()!=null){
			whereWrapper.eq("inventory",where.getInventory());
		}
        if(where.getMaximum_inventory()!=null){
			whereWrapper.eq("maximum_inventory",where.getMaximum_inventory());
		}
        if(where.getFill_morrow()!=null){
			whereWrapper.eq("fill_morrow",where.getFill_morrow());
		}
        if(where.getWeight()!=null){
			whereWrapper.eq("weight",where.getWeight());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    private QueryWrapper<QrShoppingCartView> InitWrapperView(QrShoppingCartView where){
        QueryWrapper<QrShoppingCartView> whereWrapper = new QueryWrapper<QrShoppingCartView>();
        if(where.getCart_id()!=null){
			whereWrapper.eq("cart_id",where.getCart_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getCategory_id()!=null){
			whereWrapper.eq("category_id",where.getCategory_id());
		}
        if(where.getName()!=null){
			whereWrapper.eq("name",where.getName());
		}
        if(where.getLogo()!=null){
			whereWrapper.eq("logo",where.getLogo());
		}
        if(where.getMin_buy()!=null){
			whereWrapper.eq("min_buy",where.getMin_buy());
		}
        if(where.getUnit()!=null){
			whereWrapper.eq("unit",where.getUnit());
		}
        if(where.getIntro()!=null){
			whereWrapper.eq("intro",where.getIntro());
		}
        if(where.getDescription()!=null){
			whereWrapper.eq("description",where.getDescription());
		}
        if(where.getTags()!=null){
			whereWrapper.eq("tags",where.getTags());
		}
        if(where.getCreate_time()!=null){
			whereWrapper.eq("create_time",where.getCreate_time());
		}
        if(where.getUnsend()!=null){
			whereWrapper.eq("unsend",where.getUnsend());
		}
        if(where.getSpec_id()!=null){
			whereWrapper.eq("spec_id",where.getSpec_id());
		}
        if(where.getSpec_name()!=null){
			whereWrapper.eq("spec_name",where.getSpec_name());
		}
        if(where.getPrice()!=null){
			whereWrapper.eq("price",where.getPrice());
		}
        if(where.getOriginal_price()!=null){
			whereWrapper.eq("original_price",where.getOriginal_price());
		}
        if(where.getPackage_price()!=null){
			whereWrapper.eq("package_price",where.getPackage_price());
		}
        if(where.getInventory()!=null){
			whereWrapper.eq("inventory",where.getInventory());
		}
        if(where.getMaximum_inventory()!=null){
			whereWrapper.eq("maximum_inventory",where.getMaximum_inventory());
		}
        if(where.getFill_morrow()!=null){
			whereWrapper.eq("fill_morrow",where.getFill_morrow());
		}
        if(where.getWeight()!=null){
			whereWrapper.eq("weight",where.getWeight());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    /**
     * 购物车新增
     * @param model 购物车实体
     * @return 影响行数
     */
	@Override
    public Integer add(QrShoppingCart model){
        return qrShoppingCartMapper.insert(model);
    }

    /**
     * 购物车修改byid
     * @param model 购物车实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrShoppingCart model) {
        return qrShoppingCartMapper.updateById(model);
    }

    /**
     * 购物车修改by条件
     * @param model 购物车实体
     * @param where 购物车条件
     * @return 影响行数
     */
	@Override
    public Integer update(QrShoppingCart model, Wrapper<QrShoppingCart> where) {
        return qrShoppingCartMapper.update(model, where);
    }

    /**
     * 购物车修改by条件-自动封装Wrapper
     * @param model 购物车实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrShoppingCart model, QrShoppingCart where) {
        Wrapper<QrShoppingCart> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 购物车修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("qr_shopping_cart", fields, where, params);
    }

    /**
     * 购物车删除byid
     * @param id 购物车主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return qrShoppingCartMapper.deleteById(id);
    }

    /**
     * 购物车删除by条件
     * @param where 购物车条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<QrShoppingCart> where) {
        return qrShoppingCartMapper.delete(where);
    }

    /**
     * 购物车删除by条件-自动封装Wrapper
     * @param where 购物车条件
     * @return 影响行数
     */
    @Override
    public Integer del(QrShoppingCart where) { 
        Wrapper<QrShoppingCart> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 购物车批量删除byid
     * @param ids 购物车主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return qrShoppingCartMapper.deleteBatchIds(ids);
    }

    /**
     * 购物车批量删除bymap条件
     * @param map 购物车map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return qrShoppingCartMapper.deleteByMap(map);
    }

    /**
     * 购物车详情byid
     * @param id 购物车主键
     * @return 购物车详情
     */
	@Override
    public QrShoppingCartView info(int id){
        return qrShoppingCartMapperView.selectById(id);
    }

    /**
     * 购物车详情by条件
     * @param where 购物车条件
     * @return 购物车详情
     */
	@Override
    public QrShoppingCartView info(Wrapper<QrShoppingCartView> where){
        return qrShoppingCartMapperView.selectOne(where);
    }

    /**
     * 购物车详情by条件-自动封装Wrapper
     * @param where 购物车条件
     * @return 购物车详情
     */
	@Override
    public QrShoppingCartView info(QrShoppingCartView where) {
        Wrapper<QrShoppingCartView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 购物车详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public QrShoppingCart info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "qr_shopping_cart", where, params, QrShoppingCart.class, mappings);
    }

    /**
     * 购物车批量查询byid
     * @param ids 购物车主键集合
     * @return 购物车列表
     */
	@Override
    public List<QrShoppingCartView> select(List<Integer> ids){
        return qrShoppingCartMapperView.selectBatchIds(ids);
    }

    /**
     * 购物车批量查询by条件
     * @param where 购物车条件
     * @return 购物车列表
     */
	@Override
    public List<QrShoppingCartView> select(Wrapper<QrShoppingCartView> where){
        return qrShoppingCartMapperView.selectList(where);
    }

    /**
     * 购物车批量查询by条件-自动封装Wrapper
     * @param where 购物车条件
     * @return 购物车列表
     */
    @Override
    public List<QrShoppingCartView> select(QrShoppingCartView where) {
        Wrapper<QrShoppingCartView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 购物车批量查询bymap条件
     * @param map 购物车map条件
     * @return 购物车列表
     */
	@Override
    public List<QrShoppingCartView> select(Map<String,Object> map){
        return qrShoppingCartMapperView.selectByMap(map);
    }

    /**
     * 购物车批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<QrShoppingCartView> select(IPage<QrShoppingCartView> page, Wrapper<QrShoppingCartView> where){
        return qrShoppingCartMapperView.selectPage(page, where);
    }

    /**
     * 购物车批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<QrShoppingCartView> select(IPage<QrShoppingCartView> page, QrShoppingCartView where) {
		Wrapper<QrShoppingCartView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 购物车查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<QrShoppingCartView> where){
        return qrShoppingCartMapperView.selectCount(where);
    }

    /**
     * 购物车查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(QrShoppingCartView where){
		Wrapper<QrShoppingCartView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 购物车批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<QrShoppingCartView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "qr_shopping_cart", where, orderBy, params, pageNumber, pageSize, QrShoppingCartView.class,mappings);
    }

    /**
     * 购物车批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<QrShoppingCartView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"qr_shopping_cart",where,params,QrShoppingCartView.class,mappings);
    }
}